package com.zack.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ServerUtil {
	

	private static List<Socket> clientList = new ArrayList<>();
	
	private static HashMap<Integer, ObjectOutputStream> outMap = new HashMap<>();
	
	private static HashMap<Integer, ObjectInputStream> inMap = new HashMap<>();
	
	  private static void removeClient(Socket socket) {
		   clientList.remove(socket);
		   System.out.println("====="+socket.getPort()+"断开链接=====当前在线："+clientList.size());
	   }
	   
	  private static void removeOut(int port){
		   outMap.remove(port);
	   }
	  
	  private static void removeIn(int port){
		   inMap.remove(port);
	   }
	  
	  public static void removenClientInfo(Socket socket){
		  removeClient(socket);
		  removeOut(socket.getPort());
		  removeIn(socket.getPort());
	  }
	  
	  public static void addClient(Socket socket){
		  clientList.add(socket);
	  }
	  
	  public static void addOutToMap(int port,ObjectOutputStream out){
		  outMap.put(port, out);
	  }
	  
	  public static void addInToMap(int port,ObjectInputStream in){
		  inMap.put(port, in);
	  }
	
	public static ObjectInputStream getInByPort(Integer port){
		return inMap.get(port);
	}
	
	public static ObjectOutputStream getOutByPort(Integer port){
		return outMap.get(port);
	}
	

	public static List<Socket> getClientList() {
		return clientList;
	}



}
